package com.bw.a1908.core.http;

import com.bw.a1908.core.http.base.FileProductImpl;
import com.bw.a1908.core.http.base.IFactory;
import com.bw.a1908.core.http.base.IProduct;
import com.bw.a1908.core.http.base.NetWorkProductImpl;
import com.bw.a1908.core.http.base.ProductType;

/**
 * 网络工厂
 */
public class HttpFactory implements IFactory {

    private static HttpFactory factory;

    public static HttpFactory getInstance() {
        if (factory == null) {
            factory = new HttpFactory();
        }
        return factory;
    }

    private NetWorkProductImpl netWorkProduct;
    private FileProductImpl fileProduct;

    @Override
    public IProduct create(ProductType type) {
        switch (type) {
            default:
            case NETWORK:
                if (netWorkProduct == null) {
                    netWorkProduct = new NetWorkProductImpl();
                }
                return netWorkProduct;
            case FILE:
                if (fileProduct == null) {
                    fileProduct = new FileProductImpl();
                }
                return fileProduct;
        }
    }
}
